﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using ServerBase.LunarSocket;
using ServerBase.Protocol;
using UtilLib;
using static ServerBase.Config.Conf;
using static ServerBase.Service.BaseDispatch;
using static UtilPublic.Redis.ServerRedis;
using ServerGame.Service;
using System.Collections.Generic;
using UtilPublic.ServerLoger;
using ServerBase.Service;
using ServerBase.Config;
using System;
using ServerBase.Other;
using System.Linq;
using ServerPublic.Manager;
using ServerGame.GameObject;
using static ServerGame.Service.Dispatcher;
using System.Diagnostics;
using ServerPublic.DataBaseMysql;
using UtilPublic.ApiDispatcher;
using ServerPublic.Data;
using ServerGame.Data;

namespace ServerGame.Manager
{
    public partial class DispatcherMsg
    {
        [ApiDpPro((short)EProtocolId.C2G_BASE_PING, "Ping服务器")]
        public short OnBasePing()
        {
            var Rsp = new G2C_Base_Ping()
            {
                ServerTime = DateTime.Now,
            };
            return Send(Rsp);
        }
        [ApiDpPro((short)EProtocolId.C2G_BASE_CONFIRM, "消息确认")]
        public short OnBaseConfirm()
        {
            var Rsp = new G2C_Base_Confirm();
            return Send(Rsp);
        }

        [ApiDpPro((short)EProtocolId.C2G_INFO_GETALL, "玩家全部信息")]
        public short OnInfoGetAll()
        {
            var player = (Player)ThisSession.SessionObj;
            var Rsp = new G2C_Info_GetAll()
            {
                InfoBase = player.GetInfoBase(),
                InfoMisc = player.GetInfoMisc(),
                InfoGame = player.GetInfoGame(),
            };
            player.GetInfoProp(ref Rsp.InfoProp);
            player.GetInfoProp(ref Rsp.DictProp);
            return Send(Rsp);
        }
        [ApiDpPro((short)EProtocolId.C2G_INFO_CHANGEFLAGCLIENT, "更改客户端特殊标记")]
        public short OnInfoChangeFlagClient()
        {
            var player = (Player)ThisSession.SessionObj;
            (var Req, var Rsp) = ThisReq.Body.OnInfoChangeFlagClient();

            Rsp.FlagKey = Req.FlagKey;
            Rsp.FlagValue = Req.FlagValue;

            player.DaMisc.DictFlagClient[Rsp.FlagKey] = Rsp.FlagValue;

            return Send(Rsp);
        }
        [ApiDpPro((short)EProtocolId.C2G_INFO_CHANGEFLAGCLIENTDAILY, "更改客户端特殊标记每日")]
        public short OnInfoChangeFlagClientDaily()
        {
            var player = (Player)ThisSession.SessionObj;
            (var Req, var Rsp) = ThisReq.Body.OnInfoChangeFlagClientDaily();

            Rsp.FlagKey = Req.FlagKey;
            Rsp.FlagValue = Req.FlagValue;

            player.DaMisc.DictFlagClientDaily[Rsp.FlagKey] = Rsp.FlagValue;

            return Send(Rsp);
        }
        [ApiDpPro((short)EProtocolId.C2G_INFO_PLAYERFIND, "玩家单条信息")]
        public short OnInfoPlayerFind()
        {
            (var Req, var Rsp) = ThisReq.Body.OnInfoPlayerFind();

            if (!DataGame.GetPlayer(Req.Id, out var ppp))
            {
                Rsp.Result = EProtocolResult.玩家不存在; return Send(Rsp);
            }
            Rsp.InfoPlayer = ppp.GetInfoPlayer();

            return Send(Rsp);
        }
    }
}